package com.enjoyor.soa.traffic.util.bean.rest;

import java.util.HashMap;
import java.util.Map;

import com.enjoyor.soa.traffic.util.bean.base.BaseResult;

public class RestResult extends BaseResult {

    private static final long serialVersionUID = -3744411699904480771L;

    private String message;
    private Object data;

    public RestResult() {
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public RestResult(BaseResult.Status status, Object response) {
        super(status, response);
        if (BaseResult.Status.OK.equals(status)) {
            Map<String, Object> data = new HashMap();
            data.put("ok", response);
            this.data = data;
        }
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void addData(OperatorType ot, Object data) {
        this.message = (ot.getType() + "成功");
        this.data = data;
    }

    public static enum OperatorType {
        QUERY(1, "查询"), OPERATE(16, "操作"), CREATE(17, "创建"), UPDATE(18, "更新"), DELETE(19, "删除");

        private int code;
        private String type;

        private OperatorType(int code, String type) {
            this.type = type;
        }

        public int getCode() {
            return this.code;
        }

        public String getType() {
            return this.type;
        }
    }

}
